Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(measurement): allowing measurements under crypto_nossl feature #250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jakubDoka
Copy link

@jakubDoka jakubDoka commented Nov 19, 2024

Make the measurement module compatible with the crypto_nossl feature, so openssl feature is not required.

src/certs/snp/ca/mod.rs Show resolved Hide resolved
src/measurement/gctx.rs Outdated Show resolved Hide resolved
src/measurement/sev_hashes.rs Outdated Show resolved Hide resolved
@tylerfanelli
Copy link
Member

Also, could you please provide a more in-depth commit title and description, as well as a Signed-off-by to the commit?

@tylerfanelli
Copy link
Member

Yea, I guess it was exhaustive and not necessary due to the parent module already having the any(openssl, crypto_nossl), but i guess it doesn't hurt. Please squash the commits and otherwise LGTM.

Signed-off-by: Jakub Doka <[email protected]>

Update src/measurement/sev_hashes.rs

Co-authored-by: Tyler Fanelli <[email protected]>
Signed-off-by: Jakub Dóka <[email protected]>

Update src/measurement/gctx.rs

Co-authored-by: Tyler Fanelli <[email protected]>
Signed-off-by: Jakub Dóka <[email protected]>

Update gctx.rs

Signed-off-by: Jakub Dóka <[email protected]>

Update sev_hashes.rs

Signed-off-by: Jakub Dóka <[email protected]>
@DGonzalezVillal
Copy link
Member

Could you also enable the measurement testing under the crypto_nossl flag?

it should be under tests/measurement.rs. That way we can confirm the tests are passing with the changes you committed.

Copy link
Member

@DGonzalezVillal DGonzalezVillal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nit pick, once you fix the testing, we can make sure it is working as intended and then you should be good!

@@ -12,6 +13,14 @@ use crate::{
measurement::snp::{SnpLaunchDigest, LD_BYTES},
};

#[cfg(all(not(feature = "openssl"), feature = "crypto_nossl"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library won't compile if both crypto_nossl and openssl are both passed as features, so you can just gate under crypto_nossl

Suggested change
#[cfg(all(not(feature = "openssl"), feature = "crypto_nossl"))]
#[cfg(feature = "crypto_nossl")]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was my mistake, apologies @jakubDoka

@@ -18,6 +20,14 @@ use crate::error::*;

type Sha256Hash = [u8; 32];

#[cfg(all(not(feature = "openssl"), feature = "crypto_nossl"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing

Suggested change
#[cfg(all(not(feature = "openssl"), feature = "crypto_nossl"))]
#[cfg(feature = "crypto_nossl")]

Copy link
Member

@tylerfanelli tylerfanelli Nov 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, my mistake. I asked @jakubDoka to add this forgetting that it won't compile with both features.

@DGonzalezVillal
Copy link
Member

And you still need to sign-off the commit

@@ -363,7 +363,7 @@ mod snp_tests {
}
}

#[cfg(all(target_os = "linux", feature = "sev"))]
#[cfg(all(target_os = "linux", feature = "sev", feature = "openssl"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you only add support for SNP?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I guess the commit title says otherwise, I can add that too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the biggest deal. Legacy SEV support will be deprecated soon

@jakubDoka
Copy link
Author

jakubDoka commented Nov 22, 2024

https://github.com/virtee/sev/blob/main/src/lib.rs#L89

here I see you are enforcing xor featuring, that can be incredibly annoying if you use this crate indirectly and other features end up enabled out of your control, the crate features should just work together no matter the combination you choose

@DGonzalezVillal
Copy link
Member

https://github.com/virtee/sev/blob/main/src/lib.rs#L89

here I see you are enforcing xor featuring, that can be incredibly annoying if you use this crate indirectly and other features end up enabled out of your control, the crate features should just work together no matter the combination you choose

When the crypto_nossl feature was implemented, it essentially just re-wrote functions that used openssl to use an alternative. To avoid redundancy in code the decision was you had to pick if you were going to use openssl or if you were going to use no_ssl, but you can't compile both at the same time. It makes sense although because why would you want 2 features that do the same thing? It also reduces package dependencies at compile time and avoids other issues. What features are being enabled out of your control?

@jakubDoka
Copy link
Author

jakubDoka commented Nov 22, 2024

When the crypto_nossl feature was implemented, it essentially just re-wrote functions that used openssl to use an alternative. To avoid redundancy in code the decision was you had to pick if you were going to use openssl or if you were going to use no_ssl, but you can't compile both at the same time. It makes sense although because why would you want 2 features that do the same thing? It also reduces package dependencies at compile time and avoids other issues. What features are being enabled out of your control?

Let's say you depend on a crate A that uses sev and since it does not need to use any openssl-only features, the author decides to use crypto_nossl, but then you also import crate B, this crate is using some features of the sev that require openssl thus you end up with both openssl and crypto_nossl being enabled because rust will not compile the crate for each set of features it's used with, it takes a union of features from all imports. Once you get to this configuration, you will get the compiler error from a dependency and your only saving grace is either, the author of a crate A offers you to switch to the openssl feature, or not use either of A or B.

Another scenario where this is annoying is when you have .eg wasm and native crates in your project and since openssl does not work in that environment, you are forced to use crypto_nossl, then if you still need to use openssl in the native crate, rust-analyzer gets bricked on the compiler error and you need to the do conditional imports in your cargo toml to pick different features for native and wasm even though the crate is never compiled to native code.

Note: if it's not yet possible to compile this crate to wasm, I have an interest in making that possible, but first things need to not depend on OpenSSL

@tylerfanelli
Copy link
Member

tylerfanelli commented Nov 23, 2024

So you're suggesting that we allow both openssl and crypto_nossl features concurrently (ie removing the compiler error) in this case? I'm not totally against it, but I would expect that if both are enabled, one of them (IMO openssl) would take precedent. That is, if you enable both crypto_nossl AND openssl, it would essentially be the same as enabling openssl only.

But I guess this would still break your use case when compiling to wasm as you mentioned above. Is this true?

@jakubDoka
Copy link
Author

No, in the case of compiling to the Wasm example, this is only an issue when using a workspace and Rust analyzer. Once you build the Wasm crate, you need to make sure OpenSSL is not enabled, which is the case because you have to compile each architecture separately. It's just that rust-analizer runs cargo check for all crates in the workspace

@jakubDoka
Copy link
Author

@tylerfanelli In any case, I can still apply the changes @DGonzalezVillal is asking for, xor featuring is not that important, I mainly want to move on with this. I have more PRs planned as I need snp measurement and guest side of attestation to be cross-platform (macOS, Windows, WASM if possible)

@ghe0
Copy link

ghe0 commented Dec 27, 2024

Hello!

Can you please let us know which modifications are still needed to close this PR?

Comment on lines +87 to +90
#[cfg(feature = "openssl")]
{
Ok(launch_hash.finish())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attribute macros do not allow you to define scope in this way, so this won't actually work. If you are attempting to check at run-time, you will have to use a declarative function-like macro (cfg!), instead.

Comment on lines +128 to +131
#[cfg(feature = "openssl")]
{
Ok(launch_hash.finish())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies here. Attribute macros have no concept of scope in this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants